var wheelSurf = {
    //老虎机抽奖功能
    wheelSurf: function(){
        var gRunning = false;
        $(".btn-start").click(function(){
            //如果在运行返回
            if(gRunning){
                return;
            }
            gRunning = true;
            //开始循环
            changeClass(parseInt(Math.random()*50));
        });
        function changeClass(time){
            var activeItem = $(".item.active");
            var activeIndex = activeItem.data("index");
            var max = $(".item").length;
            var nextTime = time + 5 * time /50;
            var nextIndex = 1;
            var nextItem = null;
            //如果激活了最后一个，则下一个变为第一个
            if(activeIndex == max){
                nextIndex = 1;
            }else{
                nextIndex = activeIndex + 1;
            }
            //为当前激活元素移除状态，激活下一个元素
            activeItem.removeClass("active");
            nextItem = $("td[data-index="+ nextIndex +"]");
            nextItem.addClass("active");
            //如果时间超过阀值就结束回调
            if(time>800){
                gRunning = false;
                alert("恭喜你获得了:"+nextItem.text())
            }else{
                window.setTimeout(function(){
                    changeClass(nextTime);
                },nextTime)
            }
        }
    }

};


